package com.test.pack1.demo.d2;

import org.jetbrains.annotations.NotNull;

import java.util.Iterator;

/**
 * Created by dws on 2017/11/10.
 */
public class Queue<Item> implements Iterable<Item> {

    private Node first;
    private Node last;
    private int N;
    private class Node{
        Item item;
        Node next;
    }
    public boolean isEmpty(){return first == null;}
    public int size(){return  N;}
    public void enqueue(Item item){
        Node oldlast = last;
        last = new Node();
        last.item = item;
        last.next = null;
        if (isEmpty()) first = last;
        else oldlast.next = last;
        N++;
    }
    public Item dequeue(){
        Item item = first.item;
        first = first .next;
        if(isEmpty())last =null;
        N--;
        return item;
    }




    @NotNull
    @Override
    public Iterator<Item> iterator() {
        return null;
    }
}
